package com.bestcem.xm.member.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.PageUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.bestcem.xm.common.core.domain.web.ServiceResult;
import com.bestcem.xm.common.core.sql.SQLConditionCompiler;
import com.bestcem.xm.common.core.uitls.DateUtil;
import com.bestcem.xm.common.core.uitls.JsonUtil;
import com.bestcem.xm.member.constant.CollectionConstant;
import com.bestcem.xm.member.constant.Constants;
import com.bestcem.xm.member.dao.*;
import com.bestcem.xm.member.entity.mongo.ExtendFieldValue;
import com.bestcem.xm.member.entity.mysql.MemberProjectEntity;
import com.bestcem.xm.member.entity.pojo.ExtendFieldEnumItemDO;
import com.bestcem.xm.member.entity.pojo.MemberDO;
import com.bestcem.xm.member.entity.pojo.MemberUserGroupDO;
import com.bestcem.xm.member.entity.pojo.ProjectDO;
import com.bestcem.xm.member.enums.ExtendFieldTypeEnum;
import com.bestcem.xm.member.enums.MemberTypeEnum;
import com.bestcem.xm.member.enums.NewMemberStatusEnum;
import com.bestcem.xm.member.grpc.service.param.PageParam;
import com.bestcem.xm.member.grpc.service.param.extendfield.BatchUpdateFieldsParam;
import com.bestcem.xm.member.grpc.service.param.extendfield.ExtendFieldValueParam;
import com.bestcem.xm.member.grpc.service.param.extendfield.UpdateEnumItemParam;
import com.bestcem.xm.member.grpc.service.param.extendfield.UpdateFieldParam;
import com.bestcem.xm.member.grpc.service.param.project.*;
import com.bestcem.xm.member.service.ConvertUtil;
import com.bestcem.xm.member.service.DisplayRangeService;
import com.bestcem.xm.member.service.MemberUserGroupService;
import com.bestcem.xm.member.service.ProjectService;
import com.bestcem.xm.member.service.dto.PageDTO;
import com.bestcem.xm.member.service.dto.ProjectDto;
import com.bestcem.xm.member.service.dto.ProjectMemberDto;
import com.bestcem.xm.member.service.param.ProjectManagerDynamicSql;
import com.bestcem.xm.member.util.MemberUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author dc.wang <dc.wang@idiaoyan.com>
 * @version V1.0
 * @description 联系人项目业务层实现类
 * @date 2021/7/19
 */
@Slf4j
@Service
public class ProjectServiceImpl implements ProjectService {
    private final ProjectDao projectDao;

    private final MemberDao memberDao;

    private final ExtendFieldDao extendFieldDao;

    private final ExtendFieldEnumItemDao extendFieldEnumItemDao;

    private final DisplayRangeService displayRangeService;

    @Autowired
    private MemberUserGroupDao memberUserGroupDao;

    @Autowired
    private MemberUserGroupService memberUserGroupService;

    @Resource
    private MemberUtil memberUtil;

    @Autowired
    public ProjectServiceImpl(ProjectDao projectDao, MemberDao memberDao, ExtendFieldDao extendFieldDao, ExtendFieldEnumItemDao extendFieldEnumItemDao, DisplayRangeService displayRangeService) {
        this.memberDao = memberDao;
        this.projectDao = projectDao;
        this.extendFieldDao = extendFieldDao;
        this.extendFieldEnumItemDao = extendFieldEnumItemDao;
        this.displayRangeService = displayRangeService;
    }

    @Override
    public ServiceResult<Boolean> validateName(@NotNull ValidateNameParam validateNameParam) {
        ProjectDO projectDo = projectDao.findByNameOrCode(validateNameParam.getOrgId(), validateNameParam.getProjectName(), "");
        return ServiceResult.success(projectDo != null);
    }

    @Override
    public ServiceResult<ProjectDto> getProject(@NotNull GetProjectParam getProjectParam) {
        ProjectDO project = projectDao.findById(getProjectParam.getOrgId(), getProjectParam.getId());
        if (project == null) {
            log.error("项目不存在 ：{}", getProjectParam);
            return ServiceResult.fail("项目不存在");
        }

        ProjectDto projectDto = this.convertFrom(project);
        // 处理 数据
        parseProjectInfo(projectDto, getProjectParam.getUserId(), getProjectParam.getOrgId(), false);
        // 处理扩展字段 日期格式
        parseExtendField(projectDto.getExtendFieldValues());

        return ServiceResult.success(projectDto);
    }

    /**
     * 处理扩展字段 日期格式
     *
     * @param extendFieldValues
     */
    private void parseExtendField(List<ExtendFieldValue> extendFieldValues) {
        if (CollectionUtil.isNotEmpty(extendFieldValues)) {
            extendFieldValues.forEach(field -> {
                    String fieldValue = Optional.ofNullable(field.getFieldValue()).orElse("").toString();
                if (StrUtil.isEmpty(fieldValue)) {
                    // 没有值 直接跳过
                    return;
                }
                if (field.getFieldType() == ExtendFieldTypeEnum.DATETIME.getIndex()) {
                    // 日期格式
                    DateTime parse = cn.hutool.core.date.DateUtil.parse(fieldValue);
                    field.setFieldValue(parse.toString("yyyy/MM/dd"));
                }
            });
        }
    }

    /**
     * 处理 项目信息
     *
     * @param projectDto
     * @param userId
     * @param orgId
     */
    private void parseProjectInfo(ProjectDto projectDto, String userId, String orgId, Boolean isList) {
        if (isList) {
            // 客户经理
            String accountManager = projectDto.getAccountManager();
            if (StrUtil.isNotEmpty(accountManager)) {
                // 从member表中获取客户经理的信息
                MemberDO member = memberDao.findById(accountManager);
                projectDto.setAccountManager(ObjectUtil.isNotEmpty(member) ? member.getName() : "");
            }
        }
        // 处理联系方式是否可见 与机构联系人的可以见方式相同
        Boolean displayContact =
                displayRangeService.isDisplayContact(orgId, MemberTypeEnum.INSTITUTION.getIndex(), userId);
        projectDto.setProjectManagerMobile(MemberUtil.handleMobile(projectDto.getProjectManagerMobile(), displayContact));
    }

    @Override
    public ServiceResult<List<ProjectDto>> listProjects(@NotNull ListProjectsParam listProjectsParam) {
        List<ProjectDO> projects = projectDao.findByIds(listProjectsParam.getOrgId(), listProjectsParam.getIds());
        if (CollectionUtils.isEmpty(projects)) {
            return ServiceResult.success(new ArrayList<>(0));
        }
        List<ProjectDto> projectDtos = projects.stream().map(this::convertFrom).collect(Collectors.toList());
//        if (CollUtil.isNotEmpty(projectDtos)) {
//            final String userId = listProjectsParam.getUserId();
//            final String orgId = listProjectsParam.getOrgId();
//            projectDtos.forEach( projectDto -> {
//                // 处理 数据
//                parseProjectInfo(projectDto, userId, orgId);
//                // 处理扩展字段 日期格式
//                parseExtendField(projectDto.getExtendFieldValues());
//            });
//        }
        return ServiceResult.success(projectDtos);
    }

    @Override
    public ServiceResult<List<ProjectDto>> listProjectsByIds(@NotEmpty Collection<String> projectIds) {
        List<ProjectDO> projects = projectDao.findByIds(projectIds);
        if (CollectionUtils.isEmpty(projects)) {
            return ServiceResult.success();
        }
        List<ProjectDto> projectDtos = projects.stream().map(this::convertFrom).collect(Collectors.toList());
        return ServiceResult.success(projectDtos);
    }

    @Override
    public ServiceResult<PageDTO<ProjectDto>> listMemberProjects(@NotNull ListMemberProjectsParam param) {
        // 如果分页参数不存在，查询所有项目
        PageParam pageParam = param.getPageParam();
        if (pageParam == null) {
            pageParam = new PageParam();
        }

        // 偏移量
        Integer offset = pageParam.getPage() * pageParam.getSize();
        // 查询总数
        Integer count = projectDao.countByMemberId(param.getOrgId(), param.getMemberId());
        if(offset >= count){
            return ServiceResult.success(new PageDTO<>(new ArrayList<>(0), count));
        }

        List<ProjectDO> projects = projectDao.listByMemberId(param.getOrgId(), param.getMemberId(), offset, pageParam.getSize());

        List<ProjectDto> projectDtos = projects.stream().map(this::convertFrom).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(projectDtos)) {
            final String userId = param.getUserId();
            final String orgId = param.getOrgId();
            projectDtos.forEach(projectDto -> {
                // 处理 数据
                parseProjectInfo(projectDto, userId, orgId, true);
                // 处理扩展字段 日期格式
                parseExtendField(projectDto.getExtendFieldValues());
            });
        }
        return ServiceResult.success(new PageDTO<>(projectDtos, count));
    }

    @Override
    public ServiceResult<PageDTO<ProjectMemberDto>> fuzzySearchProjectManager(@NotNull FuzzySearchProjectParam param) {
        ListFilterProjectManagerParam listFilterProjectManagerParam = new ListFilterProjectManagerParam();
        listFilterProjectManagerParam.setOrgId(param.getOrgId());
        listFilterProjectManagerParam.setUserId(param.getUserId());
        listFilterProjectManagerParam.setRegex(param.getRegex());
        listFilterProjectManagerParam.setSuperRole(param.getSuperRole());
        listFilterProjectManagerParam.setIsSenior(param.getIsSenior());
        listFilterProjectManagerParam.setDeliveryTypeEnum(param.getDeliveryTypeEnum());
        listFilterProjectManagerParam.setMemberTypeEnum(param.getMemberTypeEnum());
        listFilterProjectManagerParam.setPageParam(param.getPageParam());
        return this.listFilterProjectManager(listFilterProjectManagerParam);
    }

    @Override
    public ServiceResult<String> createProject(@NotNull CreateProjectParam createProjectParam) {
        // 校验当前联系人下项目名称、编号是否已存在
        boolean existsProjectName = projectDao.existsMemberProjectNameOrCode(createProjectParam.getOrgId(), createProjectParam.getMemberId(), createProjectParam.getName(), createProjectParam.getCode());
        if (existsProjectName) {
            log.error("项目名称/编号已存在：{}", createProjectParam);
            return ServiceResult.fail("项目名称/编号已存在");
        }

        ProjectDO project = this.convertFrom(createProjectParam);
        project.setCreateTime(DateUtil.getCommonDate());
        project.setUpdateTime(project.getCreateTime());
        ProjectDO createdProject = projectDao.insert(project);
        return ServiceResult.success(createdProject.getProjectId());
    }

    @Override
    public ServiceResult<String> updateProject(@NotNull UpdateProjectParam updateProjectParam) {
        ProjectDO beforeProject = projectDao.findById(updateProjectParam.getOrgId(), updateProjectParam.getId());
        if (beforeProject == null) {
            log.error("联系人项目不存在:{}", updateProjectParam);
            return ServiceResult.fail("联系人项目不存在");
        }

        // 校验项目编号、名称是否重复
        boolean needCheckCodeOrName = !updateProjectParam.getName().equals(beforeProject.getName()) ||
                StringUtils.hasText(updateProjectParam.getCode()) && !updateProjectParam.getCode().equals(beforeProject.getCode());
        if(needCheckCodeOrName &&
                projectDao.findByNameOrCode(updateProjectParam.getOrgId(), updateProjectParam.getName(), updateProjectParam.getCode()) != null){
            log.error("项目名称、编号已存在：{}", updateProjectParam);
            return ServiceResult.fail("项目名称、编号已存在");
        }

        ProjectDO project = this.convertFrom(updateProjectParam);
        project.setUpdateTime(DateUtil.getCommonDate());

        Integer integer = projectDao.update(project);
        if (integer == 0) {
            log.error("更新项目失败：{}", project);
            return ServiceResult.fail("更新项目失败");
        }
        return ServiceResult.success(updateProjectParam.getId());
    }

    /**
     * 修改项目扩展字段
     *
     * @param param 批量更新参数
     * @return
     */
    @Override
    public ServiceResult<Boolean> batchUpdateExtendField(BatchUpdateFieldsParam param) {
        if (!CollectionUtils.isEmpty(param.getDeleteFieldIds())) {
            // 删除联系人扩展字段
            projectDao.batchDeleteExtendFields(param.getOrgId(), param.getDeleteFieldIds());
        }

        // 更新扩展字段
        List<UpdateFieldParam> updateFieldParams = param.getUpdateFieldParams();

        if (CollectionUtils.isEmpty(updateFieldParams)) {
            return ServiceResult.success(Boolean.TRUE);
        }

        List<String> updateEnumIds = new LinkedList<>();
        Map<String, String> fieldIdAndNameMap = new HashMap<>(updateFieldParams.size());

        for (UpdateFieldParam updateFieldParam : updateFieldParams) {
            fieldIdAndNameMap.put(updateFieldParam.getId(), updateFieldParam.getName());

            // 枚举类型扩展字段才需要更新枚举选项
            if (!ExtendFieldTypeEnum.ENUM.equals(updateFieldParam.getExtendFieldTypeEnum())) {
                continue;
            }

            if (!CollectionUtils.isEmpty(updateFieldParam.getUpdateEnumItemParams())) {
                updateEnumIds.addAll(updateFieldParam.getUpdateEnumItemParams().stream().map(UpdateEnumItemParam::getId).collect(Collectors.toList()));
            }

            if (!CollectionUtils.isEmpty(updateFieldParam.getDeleteEnumItemIds())) {
                updateEnumIds.addAll(updateFieldParam.getDeleteEnumItemIds());
            }
        }

        // fixme 待修改字段先与当前字段名比较是否相同
        if (!CollectionUtils.isEmpty(fieldIdAndNameMap)) {
            projectDao.batchUpdateFieldName(param.getOrgId(), fieldIdAndNameMap);
        }

        List<ExtendFieldEnumItemDO> enumItems = extendFieldEnumItemDao.findEnumsByIds(updateEnumIds);
        if (CollectionUtils.isEmpty(enumItems)) {
            return ServiceResult.success(Boolean.TRUE);
        }
        Map<String, ExtendFieldEnumItemDO> enumItemMap = enumItems.stream().collect(Collectors.toMap(e -> e.getExtendFieldId() + e.getFieldEnumId(), Function.identity()));

        for (UpdateFieldParam updateFieldParam : updateFieldParams) {
            // 枚举类型扩展字段才需要更新枚举选项
            if (!ExtendFieldTypeEnum.ENUM.equals(updateFieldParam.getExtendFieldTypeEnum())) {
                continue;
            }

            // 更新联系人枚举选项值
            if (!CollectionUtils.isEmpty(updateFieldParam.getUpdateEnumItemParams())) {
                for (UpdateEnumItemParam ue : updateFieldParam.getUpdateEnumItemParams()) {
                    ExtendFieldEnumItemDO currentEnumItem = enumItemMap.get(updateFieldParam.getId() + ue.getId());
                    if (currentEnumItem == null) {
                        continue;
                    }
                    projectDao.updateMemberFieldEnumValue(param.getOrgId(), updateFieldParam.getId(), currentEnumItem.getName(), ue.getName());
                }
            }

            // 删除联系人枚举选项值
            if (!CollectionUtils.isEmpty(updateFieldParam.getDeleteEnumItemIds())) {
                for (String enumItemId : updateFieldParam.getDeleteEnumItemIds()) {
                    ExtendFieldEnumItemDO currentEnumItem = enumItemMap.get(updateFieldParam.getId() + enumItemId);
                    if (currentEnumItem == null) {
                        continue;
                    }
                    projectDao.updateMemberFieldEnumValue(param.getOrgId(), updateFieldParam.getId(), currentEnumItem.getName(), null);
                }
            }
        }
        return ServiceResult.success(Boolean.TRUE);
    }

    @Override
    public ServiceResult<Integer> deleteById(@NotNull DeleteProjectParam deleteProjectParam) {
        Integer count = projectDao.deleteById(deleteProjectParam.getOrgId(), deleteProjectParam.getId());
        if (count == 0) {
            log.error("删除项目失败：{}", deleteProjectParam);
            return ServiceResult.fail("删除项目失败");
        }

        return ServiceResult.success(count);
    }

    @Override
    public ServiceResult<Integer> batchDeleteByIds(@NotNull BatchDeleteProjectParam batchDeleteProjectParam) {
        Integer count = projectDao.batchDeleteByIds(batchDeleteProjectParam.getOrgId(), batchDeleteProjectParam.getIds());
        if (count == 0) {
            log.error("删除项目失败：{}", batchDeleteProjectParam);
            return ServiceResult.fail("删除项目失败");
        }
        return ServiceResult.success(count);
    }

    @Override
    public ServiceResult<String> updateProject(ProjectDO project) {
        projectDao.update(project);
        return ServiceResult.success(project.getProjectId());
    }

    @Override
    public ServiceResult<String> createProject(ProjectDO project) {
        ProjectDO projectDO = projectDao.insert(project);
        return ServiceResult.success(projectDO.getProjectId());
    }

    @Override
    public ProjectDO findOneByOrgIdAndName(String orgId, String projectName) {
        return projectDao.findByName(orgId, projectName);
    }

    @Override
    public List<ProjectDO> findByOrgIdAndMProjectCode(String orgId, String mProjectCode) {
        return projectDao.findByCode(orgId, mProjectCode);
    }

    @Override
    public ProjectDO findOneByOrgIdAndMemberIdAndName(String orgId, String mid, String projectName) {
        return projectDao.findOneByOrgIdAndMemberIdAndName(orgId, mid, projectName);
    }

    @Override
    public ServiceResult<PageDTO<ProjectMemberDto>> listFilterProjectManager(@NotNull ListFilterProjectManagerParam param) {
        ProjectManagerDynamicSql dynamicSql = new ProjectManagerDynamicSql();
        dynamicSql.setOrgId(param.getOrgId());
        dynamicSql.setStatus(NewMemberStatusEnum.MEMBER_STATUS_ACTIVATED.getIndex());
        dynamicSql.setMemberType(MemberTypeEnum.INSTITUTION.getIndex());
        dynamicSql.setDeliveryType(param.getDeliveryTypeEnum().getIndex());
        dynamicSql.setSearch(param.getRegex());

        // condition 解析成条件
        if (ObjectUtil.isNotEmpty(param.getCondition())) {
            ServiceResult<Wrapper<MemberProjectEntity>> result = SQLConditionCompiler.newInstance()
                    .compile(JsonUtil.tryConvertToJSONObject(param.getCondition()),this::projectManagerDeliveryConditionPreprocess);
            if (!result.isSuccess()) {
                return ServiceResult.fail("查询条件解析失败");
            }
            String sqlSegment = result.getData().getSqlSegment();
            dynamicSql.setWrapper(result.getData());
        }

        // 管理员不校验联系人组织层级
        Integer adminSign = 1;
        boolean isAdmin = adminSign.equals(param.getSuperRole()) || adminSign.equals(param.getIsSenior());
        dynamicSql.setAdmin(isAdmin);
        if(!isAdmin){
            // 查询用户组织层级
            ServiceResult<Collection<String>> userStoreIdsResult = memberUserGroupService.userGroupIds(param.getUserId());
            if (!userStoreIdsResult.isSuccess()) {
                if (log.isErrorEnabled()) {
                    log.error("查询用户组织层级失败({}):{}", param.getUserId(), userStoreIdsResult);
                }
                userStoreIdsResult.setData(new ArrayList<>());
            }
            Collection<String> userDirectGroupIds = userStoreIdsResult.getData();
            // 查询组织层级叶子节点、失效节点数量,如果小于阈值，那么单表查询
            Integer leafAndInactiveStoreCount = memberUserGroupDao.countSubAndInactiveGroup(param.getOrgId(), userDirectGroupIds);
            if(leafAndInactiveStoreCount < Constants.STORE_IN_SEARCH_MAX_COUNT){
                List<MemberUserGroupDO> memberStores = memberUserGroupDao.allSubAndInactiveGroup(param.getOrgId(), userDirectGroupIds);
                List<String> storeIds = memberStores.stream().map(MemberUserGroupDO::getGroupId).collect(Collectors.toList());
                dynamicSql.setUserLeafGroupIds(storeIds);
            }else{
                // 自然增序排序
                String userGroupIds = userDirectGroupIds.stream().sorted().collect(Collectors.joining("\",\"","[\"","\"]"));
                dynamicSql.setUserGroupIds(userGroupIds);
            }
        }

        Integer count = projectDao.countProjectManagerByDynamicSql(dynamicSql);
        if(count == 0){
            return ServiceResult.success(new PageDTO<>(new ArrayList<>(),0));
        }

        // 分页查询
        PageParam pageParam = param.getPageParam();
        if(param.getPageParam() != null){
            dynamicSql.setPage(PageUtil.getStart(pageParam.getPage() - 1, pageParam.getSize()));
            dynamicSql.setSize(pageParam.getSize());
        }
        List<ProjectMemberDto> projectMemberDtos = projectDao.listProjectManagerByDynamicSql(dynamicSql);

        // 根据可见性,隐藏或显示手机号和邮箱
        Boolean isDisplayContact = displayRangeService.isDisplayContact(param.getOrgId(), MemberTypeEnum.PROJECT.getIndex(), param.getUserId());
        if (Boolean.TRUE.equals(isDisplayContact)) {
            for (ProjectMemberDto dto : projectMemberDtos) {
                if (!StringUtils.hasText(dto.getProjectManagerPhone())) {
                    continue;
                }
                dto.setProjectManagerPhone(MemberUtil.handleEmail(dto.getProjectManagerPhone(), isDisplayContact));
            }
        }

        return ServiceResult.success(new PageDTO<>(projectMemberDtos, count));
    }

    private ProjectDO convertFrom(CreateProjectParam param) {
        ProjectDO res = ConvertUtil.createProjectParam2ProjectDo(param);
        if (!CollectionUtils.isEmpty(param.getExtendFieldValues())) {
             List<ExtendFieldValue> extendFieldValues = param.getExtendFieldValues().stream().map(this::convertFrom).collect(Collectors.toList());
             res.setFieldValList(JSONObject.toJSONString(extendFieldValues));
        }
        return res;
    }

    private ProjectDO convertFrom(UpdateProjectParam param) {
        ProjectDO res = ConvertUtil.updateProjectParam2ProjectDo(param);
        return res;
    }


    private ExtendFieldValue convertFrom(ExtendFieldValueParam param) {
        ExtendFieldValue res = new ExtendFieldValue();
        res.setFieldId(param.getId());
        res.setFieldType(param.getType());
        res.setFieldName(param.getName());
        res.setFieldValue(param.getValue());
        return res;
    }

    private ProjectDto convertFrom(ProjectDO project) {
        ProjectDto res = ConvertUtil.projectDO2ProjectDto(project);
        if (StrUtil.isNotEmpty(project.getFieldValList())) {
            res.setExtendFieldValues(JSONArray.parseArray(project.getFieldValList(), ExtendFieldValue.class));
        }
        return res;
    }

    private String projectManagerDeliveryConditionPreprocess(JSONObject jsonCondition){
        // 是条件组则判断深度、广度
        if(jsonCondition.containsKey("filters")){
            // 深度超过3
            int level = Optional.ofNullable(jsonCondition.getInteger("level")).orElse(1);
            if (level > 3) {
                return "条件组深度超过3";
            }
            jsonCondition.put("level", level);

            // 广度超过5
            JSONArray jsonFilters = jsonCondition.getJSONArray("filters");
            if (jsonFilters.size() > 5) {
                return "条件范围广度超过5";
            }
            return "";
        }

        // 来源
        if("project".equals(jsonCondition.getString("source"))){
            jsonCondition.put("table", CollectionConstant.PROJECT);

            // 获取前端参数映射到表的列名
//            String columnName = this.projectManagerMemberMapping(jsonCondition.getString("name"));
//            jsonCondition.put("name", columnName);
        }else{

            jsonCondition.put("table", CollectionConstant.MEMBER);
            String columnName = jsonCondition.getString("name");
            if(StringUtils.hasText(columnName) && columnName.startsWith("member.")){
                jsonCondition.put("name", columnName.substring(7));
            }

        }

        return "";
    }
}
